package com.android.controller;

import java.util.ArrayList;

import org.ksoap2.serialization.SoapObject;

import com.android.entity.Customer;

public class Customer_Controller {
	
	private static String SOAP_ACTION = "http://pa.webservice.org/getListCustomer";
	private static String METHOD_NAME = "getListCustomer";
	private static String NAMESPACE = "http://pa.webservice.org/";
	private static String URL = "http://10.0.2.2:8080/WebServiceApp/AndroidWebserviceService?WSDL";
	private static String SOAP_ACTION_1 = "http://pa.webservice.org/getCustomerByCustomerName";
	private static String METHOD_NAME_1 = "getCustomerByCustomerName";
	static ArrayList<Customer> customer_list;
	
public static Customer getCustomerFromSoapObject(SoapObject soap){
		
		Customer customer = new Customer();
			customer.setCustomer_name(soap.getProperty("customer_name").toString());
			customer.setPassword(soap.getProperty("password").toString());
			customer.setNames(soap.getProperty("names").toString());
			customer.setDataOfBirth(soap.getProperty("dateOfBirth").toString());
			customer.setPhone(soap.getProperty("phone").toString());
			customer.setAddress(soap.getProperty("address").toString());
			customer.setEmail(soap.getProperty("email").toString());
		return customer;
		
	}

	public static Customer getCustomerByName(String name){
//		SoapObject soaps = connect.getConnectionFromWebservice(METHOD_NAME_1, NAMESPACE, SOAP_ACTION, URL);
		SoapObject soaps = Connect_Webservice.getConnectionFromWebserviceWithPara(METHOD_NAME_1, NAMESPACE, SOAP_ACTION_1, URL, name);
//		SoapObject soap = (SoapObject)soaps.getProperty(0);
//		Customer customer = getCustomerFromSoapObject(soap);
		Customer customer = new Customer();
		customer = getCustomerFromSoapObject(soaps);
		return customer;
	}
	


	public static ArrayList<Customer> getListCustomer(){
 		
		customer_list = new ArrayList<Customer>();
		SoapObject soaps = Connect_Webservice.getConnectionFromWebservice(METHOD_NAME, NAMESPACE, SOAP_ACTION, URL);
		for(int i = 0; i< soaps.getPropertyCount(); i++){
			SoapObject soap = (SoapObject) soaps.getProperty(i);
			Customer customer_item = getCustomerFromSoapObject(soap);
			customer_list.add(customer_item);
		}
		
		return customer_list;
		
	}

}
